package cn.itsource.pet.controller;

import cn.itsource.basic.domain.AjaxResult;
import cn.itsource.basic.util.PageList;
import cn.itsource.pet.domain.Pet;
import cn.itsource.pet.domain.PetDTO;
import cn.itsource.pet.domain.SearchMasterMessageQuery;
import cn.itsource.pet.domain.StateIdsDto;
import cn.itsource.pet.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("pet")
public class PetController {

    @Autowired
    PetService petService;

    @PostMapping("pagelist")
    public PageList pagelist(@RequestBody SearchMasterMessageQuery query){
        return petService.pagelist(query);
    }

    @PostMapping("save")
    public AjaxResult save(@RequestBody PetDTO petDTO){
        return petService.save(petDTO);
    }

    /**
     * 宠物上架的方法
     * @param ids
     * @return
     */
    @PostMapping("upbutton")
    public AjaxResult upbutton(@RequestBody StateIdsDto stateIdsDto){

        return petService.upbutton(stateIdsDto);
    }

    /**
     * 批量删除的方法
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    public AjaxResult deleteBatch(@RequestBody List<Long> ids){

        return petService.deleteBatch(ids);
    }

    /**
     * 上架的方法
     * @param pet
     * @return
     */
    @PostMapping("shenghe")
    public AjaxResult shenghe(@RequestBody Pet pet){

        return petService.shenghe(pet);
    }

    @PostMapping("findAll")
    public PageList findAll(@RequestBody  SearchMasterMessageQuery query){
        return petService.findAll(query);
    }

    @GetMapping("findOne/{id}")
    public Pet findOne(@PathVariable Long id){
        Pet one = petService.findOne(id);
        System.out.println(one);
        return one;
    }

}
